
import java.util.Stack;

/**
 *
 * 用栈模拟实现队列
 */

public class MyQueue {
    private Stack<Integer> in;
    private Stack<Integer> out;
    public MyQueue() {
        in = new Stack<>();
        out = new Stack<>();
    }

    public void push(int x) {
        //元素入队时 直接将元素push进in栈
        in.push(x);
    }

    public int pop() {
        //出队时 先看out栈是否为空 不空的话直接pop out栈的元素
        //空的话就将in栈的内容pop后push进out栈
        if(out.isEmpty()){
            while(!in.isEmpty()){
                out.push(in.pop());
            }
        }
        return out.pop();
    }

    public int peek() {
        if(out.isEmpty()){
            while(!in.isEmpty()){
                out.push(in.pop());
            }
        }
        return out.peek();
    }

    public boolean empty() {
        return in.isEmpty() && out.isEmpty();
    }
}
